using BepuUtilities.Memory;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace BepuUtilities.Collections
{
    /// <summary>
    /// EqualityCompeller周围的IEqualityComperRef包装。
    /// </summary>
    /// <typeparam name="T">要比较和散列的对象的类型。</typeparam>
    public struct WrapperEqualityComparer<T> : IEqualityComparerRef<T>
    {
        public EqualityComparer<T> Comparer;
        /// <summary>
        /// 为给定类型创建默认比较器。
        /// </summary>
        /// <param name="谓词">使用此类型的默认比较器对其他项进行测试的谓词。</param>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static void CreateDefault(out WrapperEqualityComparer<T> predicate)
        {
            predicate.Comparer = EqualityComparer<T>.Default;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Equals(ref T a, ref T b)
        {
            return Comparer.Equals(a, b);
        }

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public int Hash(ref T item)
        {
            return item.GetHashCode();
        }
    }
}
